﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Melee_weapon_judge : MonoBehaviour
{
    private Animator Player_Ani;
    private Transform[] Judge_points;
    private Vector3[] Prev_Point;
    public LayerMask mask;
    public bool isAttack = false;

    // Start is called before the first frame update
    void Start()
    {
        Player_Ani = transform.parent.GetComponent<Animator>();
        Judge_points = new Transform[2];
        Prev_Point = new Vector3[2];
        Judge_points[0] = this.transform.Find("judge_point(1)");
        Judge_points[1] = this.transform.Find("judge_point(2)");
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 p0 = Judge_points[0].position;
        Vector3 p1 = Judge_points[1].position;
        RaycastHit hinfo;
        GameObject hitObj = null;
        AnimatorStateInfo stateInfo = Player_Ani.GetCurrentAnimatorStateInfo(0);

        if(stateInfo.fullPathHash == Animator.StringToHash("Base Layer.attack"))
        {
            Debug.Log("attack");
            if (Physics.Linecast(p0, Prev_Point[0], out hinfo, mask)) 
            {
                hitObj = hinfo.collider.gameObject;
            }else if(Physics.Linecast(p0, Prev_Point[1], out hinfo, mask))
            {
                hitObj = hinfo.collider.gameObject;
            }
            if(hitObj != null)
            {
                Debug.Log("近战命中：" + hitObj.name);
            }

        }

        Prev_Point[0] = p0;
    }
}
